<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%
    //String surveyId = input.getDesc("survey_id", "-1");
    String visitId = input.getDesc("visit_id", "-1");
    List<Map> visits = QBuilder.db("basedb").select("new map(id as visit_id, isconfirmed as confirm, surveyId as survey_id, reconfirmedTime as delay, cancel as push)").from("Visit").where(new Where("hospital=", hospital).and("status = ", STATUS_ENABLE).and("category=2").and("id=", visitId)).query().getResultObj();
    if (isEmpty(visits)) {
        msg = new Message(30041, "暂无详细随访信息");
        msg.put("data", new ArrayList());
        Tools.encryptPrint(out, msg);
        return;
    }
    Map map = visits.get(0);
    String surveyId = Tools.getDesc(map.get("survey_id"), "-1");
    List<Map> questions = QBuilder.db("basedb").select("new map(id as quest_id, title as title, detail as detail, type as type, CONCAT(FROM_UNIXTIME(cTime / 1000, '%Y-%m-%d %T'), '') as time, jsonString as json, showOrder as show_order)").from("SurveyQuestion").where(new Where("status = ", STATUS_ENABLE).and("surveyId=", surveyId)).order("show_order", QBuilder.asc).query().getResultObj();
    if (isEmpty(questions)) {
        msg = new Message(30041, "暂无详细随访信息");
        msg.put("data", new ArrayList());
        Tools.encryptPrint(out, msg);
        return;
    }
    for (int i = 0; i < questions.size(); i++) {
        Map sq = questions.get(i);
        String questId = Tools.getDesc(sq.get("quest_id"), "-1");
        String json = Tools.getDesc(sq.remove("json"), "");
        Map<String, String> jsonString = JSONUtil.fromJson(json, new TypeReference<Map>(){});
        sq.put("schedule", Tools.getDesc(jsonString.get("schedule"), "首次"));
        sq.put("unit", Tools.getDesc(jsonString.get("unit"), ""));
    }
    map.put("survey", questions);
    msg.put("data", map);
    Tools.encryptPrint(out, msg);
%>
